// 轮播图JS
let currentSlide = 0;
let slides, dots, carouselTimer;

function showSlide(idx) {
    slides.forEach((img, i) => {
        img.classList.toggle('active', i === idx);
        dots[i].classList.toggle('active', i === idx);
    });
    currentSlide = idx;
}
function nextSlide() {
    let idx = (currentSlide + 1) % slides.length;
    showSlide(idx);
}
function prevSlide() {
    let idx = (currentSlide - 1 + slides.length) % slides.length;
    showSlide(idx);
}
function goToSlide(idx) {
    showSlide(idx);
}
function startCarousel() {
    carouselTimer = setInterval(nextSlide, 3500);
}
function stopCarousel() {
    clearInterval(carouselTimer);
}
document.addEventListener('DOMContentLoaded', function() {
    slides = document.querySelectorAll('.carousel-img');
    dots = document.querySelectorAll('.dot');
    showSlide(0);
    startCarousel();
    document.getElementById('carousel').addEventListener('mouseenter', stopCarousel);
    document.getElementById('carousel').addEventListener('mouseleave', startCarousel);
}); 
